import os
from dashscope import Generation

# 多轮对话
msgs = [
    {'role': 'user', 'content': '我叫张三,今年18岁,性别男'}
]

resp = Generation.call(
    api_key=os.getenv("DASH_SCOPE_API_KEY"),
    model="qwen-plus",
    messages=msgs,
    result_format="message"
)

if resp.status_code == 200:
    print(resp.output.choices[0].message.content)
    msgs.append({'role': resp.output.choices[0].message.role, 'content': resp.output.choices[0].message.content})
    msgs.append({'role': 'user', 'content': '我叫什么,男的女的'})
    resp = Generation.call(
        api_key=os.getenv("DASH_SCOPE_API_KEY"),
        model="qwen-plus",
        messages=msgs,
        result_format="message"
    )
    if resp.status_code == 200:
        print(resp.output.choices[0].message.content)

else:
    print("调取错误")
